package net.xinqushi.collection;

import net.xinqushi.utils.Reflections;
import org.springframework.util.ReflectionUtils;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.function.UnaryOperator;

/**
 * @author xjie 2019/7/23 10:40
 * @description
 */
public class ArrayListTest {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList(2);
        for(int i = 0 ; i < 20 ; i++){
            Object elementData = Reflections.getFieldValue(list, "elementData");
            list.add(i+ "");
        }
        // a negative integer, zero, or a positive integer as the
        // first argument is less than, equal to, or greater than the second.
        list.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return  Integer.valueOf(o1) - Integer.valueOf(o2);
            }
        });
        list.forEach(System.out::println);

//        list.replaceAll(new UnaryOperator<String>() {
//            @Override
//            public String apply(String s) {
//                return "123";
//            }
//        });
        //list.forEach(System.out::println);

        list.subList(0,8).remove(0);//subList is share memory with his parentList

        list.forEach(System.out::println);

        list.spliterator();
    }
}
